package net.caixiaomi.info.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import net.caixiaomi.info.R;
import net.caixiaomi.info.util.Constants;
import net.caixiaomi.info.util.ToastUtil;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    private IWXAPI mApi;


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        mApi.handleIntent(intent, this);
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mApi = WXAPIFactory.createWXAPI(this, Constants.WEIXIN_APP_ID, false);
        mApi.registerApp(Constants.WEIXIN_APP_ID);
        mApi.handleIntent(getIntent(), this);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        if (baseResp instanceof SendAuth.Resp) {
            SendAuth.Resp newResp = (SendAuth.Resp) baseResp;
            //TODO 登录
        }
        //todo 分享
        if (baseResp.errCode == BaseResp.ErrCode.ERR_OK) {
            ToastUtil.s(R.string.C_SHARE_SUCESS);
        } else {
            ToastUtil.s(R.string.C_SHARE_FAIL);
        }
        finish();
    }
}
